package com.spzx.product.configure;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author 快点干早点散
 * @Create 2025/5/7 16:50
 * Description:
 */
@Configuration
public class ThreadPoolConfig {


    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        int coreSize = Runtime.getRuntime().availableProcessors();
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                coreSize*2,//核心线程数
                coreSize*2,//最大线程数
                60l,//存活时间
                TimeUnit.SECONDS,//时间单位
                new ArrayBlockingQueue<>(100),//阻塞队列
                Executors.defaultThreadFactory(),//线程工程
                new ThreadPoolExecutor.DiscardOldestPolicy()//拒绝策略
        );
        //线程会在需要时创建
        return  executor;

    }
}
